package util.boyaa.recycle 
{
	/**
	 * ...
	 * @author henrylee   Any question, pls contact me. henrylee_sz@qq.com.
	 */
	public class Recycleable implements IRecyclable 
	{
		/** 可回收对象的当前状态 */
		private var _state: int;
		/** 注册的工程对象 */
		private var _factory: IRecycleFactory;
		
		public function Recycleable() 
		{
			_state = 0;
		}
		
		public function awake():void 
		{
			_state = RecycleableVars.AWAKE;
		}
		
		public function recycle():void 
		{
			if (_state != RecycleableVars.AWAKE) return;
			_state = RecycleableVars.RECYCLE;
			if (_factory != null) _factory.recycle(this);
		}
		
		public function dispose():void 
		{
			_state = RecycleableVars.DISPOSE;
			_factory = null;
		}
		
		public function get state():int 
		{
			return _state;
		}
		
		public function registerFactory(factory:IRecycleFactory):void
		{
			_factory = factory;
		}
		
	}

}